package com.raptor.trustworthy.server.service.Impl;

import com.raptor.trustworthy.common.vo.Student;
import com.raptor.trustworthy.server.dao.GoDao;
import com.raptor.trustworthy.server.service.Gogogo;
import com.raptor.trustworthycore.util.DateUtil;
import com.raptor.trustworthypojo.pojo.TCooker;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * gogogo实现类
 *
 * @Author renhuan
 * @Date 2020-06-10 1:05
 **/
@Service
public class GogogoImpl implements Gogogo {
  private static final Logger log = LoggerFactory.getLogger(GogogoImpl.class);

  @Autowired
  private GoDao goDao;

  @Override
  public void goTrue() {
    Student student = new Student();
    student.setAge("10");
    student.setCertCode("320113");
    student.setName("zhangsan");
    log.info(student.toString());
  }

  private List<String> errorList;

  @Override
  public String setErrorList() {
    errorList = new ArrayList();
    Random r = new Random();
    String a = String.valueOf(r.nextInt(11) + 10);
    log.info("即将塞入：" + a);
    System.out.println("即将塞入：" + a);
    errorList.add(a);
    return "塞入错误数据个数：" + errorList.size();
  }

  @Override
  public String getErrorList() {
    StringBuilder sbl = new StringBuilder();
    for (String error : errorList){
      sbl.append(error).append("&");
    }
    return sbl.toString();
  }

  @Override
  public String goTest() {
    System.out.println("going gogogo");
    Date date = new Date();
    String dateStr = DateUtil.getFormatTimeString(date, DateUtil.DATE_FORMATE_STRING_K);
    System.out.println(dateStr);
    return null;
  }

  @Override
  public List<TCooker> getAllCook() {
    Long bigenTime = System.currentTimeMillis();
    System.out.println(String.format("当前时间%s,当前毫秒%s", bigenTime, new Date(bigenTime)));
    return goDao.queryAllCook();
  }

  @Override
  public List<TCooker> queryAllCookByCookerId(Long cookerId) {
    return goDao.queryAllCookByCookerId(cookerId);
  }

  @Override
  public List<TCooker> queryAllCookByCooker(TCooker tCooker) {
    Map<String, Object> paramMap = new HashMap();
    paramMap.put("testCooker", tCooker.getTestCooker());
    paramMap.put("cookerId", tCooker.getCookerid());
    return goDao.queryAllCookByCooker(paramMap);
  }
}
